package com.bestcem.xm.award.service.dto.draw;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.bestcem.xm.award.entity.pojo.AwardRecordDO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import static com.bestcem.xm.award.constant.Constants.AWARD_EXCEL_DEFAULT_COLUMN_WIDTH;
import static com.bestcem.xm.award.constant.Constants.AWARD_LEVELS;

/**
 * 中奖奖项信息DTO
 *
 * @author hang.li <hang.li@idiaoyan.com>
 * @version v1.0
 * @date 2021/7/14 16:05
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ColumnWidth(AWARD_EXCEL_DEFAULT_COLUMN_WIDTH)
public class ExportWinnerDetailDTO {

    /**
     * 兑奖码
     */
    @ExcelProperty(value = "兑奖码")
    private String code;

    /**
     * 奖项等级
     */
    @ExcelProperty(value = "奖项等级")
    private String level;

    /**
     * 奖项名称
     */
    @ExcelProperty(value = "奖项名称")
    private String name;

    /**
     * 导出中奖名单奖项信息数据转换
     *
     * @param record 抽奖记录数据
     * @return ExportWinnerDetailDTO
     */
    public static ExportWinnerDetailDTO awardRecordToExportWinnerDetailDTO(AwardRecordDO record) {
        ExportWinnerDetailDTO detailDTO = new ExportWinnerDetailDTO();
        if (record.getWin() != null) {
            detailDTO.setCode(record.getWin().getCode());
            detailDTO.setName(record.getWin().getName());
            if (StringUtils.isNotBlank(record.getWin().getLevelStr())) {
                detailDTO.setLevel(record.getWin().getLevelStr());
            } else {
                detailDTO.setLevel(AWARD_LEVELS[record.getWin().getLevel()]);
            }
        }
        return detailDTO;
    }
}
